* @return bool
*/
function loadFromMemcached( $mckey, $touched ) {
- global $wgMemc;
-
if ( !$touched ) {
return false;
}
- $mcvalue = $wgMemc->get( $mckey );
+ $mcvalue = ObjectCache::getMainWANInstance()->get( $mckey );
if ( $mcvalue ) {
# Check to see if the value has been invalidated
if ( $touched <= $mcvalue['timestamp'] ) {
* @return bool
*/
function storeInMemcached( $mckey, $expiry = 86400 ) {
- global $wgMemc;
-
- $wgMemc->set( $mckey,
+ ObjectCache::getMainWANInstance()->set( $mckey,
array(
'timestamp' => wfTimestampNow(),
'value' => $this->mText
* @return bool
*/
public static function isWhitelistedFromAutoblocks( $ip ) {
- global $wgMemc;
-
// Try to get the autoblock_whitelist from the cache, as it's faster
// than getting the msg raw and explode()'ing it.
- $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
- $lines = $wgMemc->get( $key );
- if ( !$lines ) {
- $lines = explode( "\n", wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() );
- $wgMemc->set( $key, $lines, 3600 * 24 );
- }
+
+ $lines = ObjectCache::getMainWANInstance()->getWithSetCallback(
+ wfMemcKey( 'ipb', 'autoblock', 'whitelist' ),
+ 86400,
+ function () {
+ return explode( "\n",
+ wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() );
+ }
+ );
wfDebug( "Checking the autoblock whitelist..\n" );
*/
protected function loadText() {
// Caching may be beneficial for massive use of external storage
- global $wgRevisionCacheExpiry, $wgMemc;
+ global $wgRevisionCacheExpiry;
+ $cache = ObjectCache::getMainWANInstance();
$textId = $this->getTextId();
$key = wfMemcKey( 'revisiontext', 'textid', $textId );
if ( $wgRevisionCacheExpiry ) {
- $text = $wgMemc->get( $key );
+ $text = $cache->get( $key );
if ( is_string( $text ) ) {
wfDebug( __METHOD__ . ": got id $textId from cache\n" );
return $text;
# No negative caching -- negative hits on text rows may be due to corrupted slave servers
if ( $wgRevisionCacheExpiry && $text !== false ) {
- $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
+ $cache->set( $key, $text, $wgRevisionCacheExpiry );
}
return $text;
* @return int
*/
static function numberingroup( $group ) {
- if ( !isset( self::$groupMemberCounts[$group] ) ) {
- global $wgMemc;
- $key = wfMemcKey( 'SiteStats', 'groupcounts', $group );
- $hit = $wgMemc->get( $key );
- if ( !$hit ) {
+ return ObjectCache::getMainWANInstance()->getWithSetCallback(
+ wfMemcKey( 'SiteStats', 'groupcounts', $group ),
+ 3600,
+ function ( $oldValue, &$ttl, array &$setOpts ) use ( $group ) {
$dbr = wfGetDB( DB_SLAVE );
- $hit = $dbr->selectField(
+
+ $setOpts += $dbr->getCacheSetOptions();
+
+ return $dbr->selectField(
'user_groups',
'COUNT(*)',
array( 'ug_group' => $group ),
__METHOD__
);
- $wgMemc->set( $key, $hit, 3600 );
- }
- self::$groupMemberCounts[$group] = $hit;
- }
- return self::$groupMemberCounts[$group];
+ },
+ array( 'pcTTL' => 10 )
+ );
}
/**
* @return string
*/
public static function getHelp( IContextSource $context, $modules, array $options ) {
- global $wgMemc, $wgContLang;
+ global $wgContLang;
if ( !is_array( $modules ) ) {
$modules = array( $modules );
}
$out->setPageTitle( $context->msg( 'api-help-title' ) );
+ $cache = ObjectCache::getMainWANInstance();
$cacheKey = null;
if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
$options['recursivesubmodules'] && $context->getLanguage() === $wgContLang
$cacheKey = wfMemcKey( 'apihelp', $modules[0]->getModulePath(),
(int)!empty( $options['toc'] ),
str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
- $cached = $wgMemc->get( $cacheKey );
+ $cached = $cache->get( $cacheKey );
if ( $cached ) {
$out->addHTML( $cached );
return;
$out->addHTML( $html );
if ( $cacheKey !== null ) {
- $wgMemc->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
+ $cache->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
}
}
*/
public function makeHelpMsg() {
wfDeprecated( __METHOD__, '1.25' );
- global $wgMemc;
- $this->setHelp();
- // Get help text from cache if present
- $key = wfMemcKey( 'apihelp', $this->getModuleName(),
- str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
+ $this->setHelp();
$cacheHelpTimeout = $this->getConfig()->get( 'APICacheHelpTimeout' );
- if ( $cacheHelpTimeout > 0 ) {
- $cached = $wgMemc->get( $key );
- if ( $cached ) {
- return $cached;
- }
- }
- $retval = $this->reallyMakeHelpMsg();
- if ( $cacheHelpTimeout > 0 ) {
- $wgMemc->set( $key, $retval, $cacheHelpTimeout );
- }
- return $retval;
+ return ObjectCache::getMainWANInstance()->getWithSetCallback(
+ wfMemcKey(
+ 'apihelp',
+ $this->getModuleName(),
+ str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) )
+ ),
+ $cacheHelpTimeout > 0 ? $cacheHelpTimeout : WANObjectCache::TTL_UNCACHEABLE,
+ array( $this, 'reallyMakeHelpMsg' )
+ );
}
/**
* @return int
*/
public function getNumLinks( $table, $max = INF ) {
- global $wgMemc, $wgUpdateRowsPerJob;
+ global $wgUpdateRowsPerJob;
+ $cache = ObjectCache::getMainWANInstance();
// 1) try partition cache ...
if ( isset( $this->partitionCache[$table] ) ) {
$entry = reset( $this->partitionCache[$table] );
$memcKey = wfMemcKey( 'numbacklinks', md5( $this->title->getPrefixedDBkey() ), $table );
// 3) ... fallback to memcached ...
- $count = $wgMemc->get( $memcKey );
+ $count = $cache->get( $memcKey );
if ( $count ) {
return min( $max, $count );
}
// Fetch the full title info, since the caller will likely need it next
$count = $this->getLinks( $table, false, false, $max )->count();
if ( $count < $max ) { // full count
- $wgMemc->set( $memcKey, $count, self::CACHE_EXPIRY );
+ $cache->set( $memcKey, $count, self::CACHE_EXPIRY );
}
}
* @return array
*/
public function partition( $table, $batchSize ) {
- global $wgMemc;
-
// 1) try partition cache ...
if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
wfDebug( __METHOD__ . ": got from partition cache\n" );
return $this->partitionCache[$table][$batchSize]['batches'];
}
+ $cache = ObjectCache::getMainWANInstance();
$this->partitionCache[$table][$batchSize] = false;
$cacheEntry =& $this->partitionCache[$table][$batchSize];
);
// 3) ... fallback to memcached ...
- $memcValue = $wgMemc->get( $memcKey );
+ $memcValue = $cache->get( $memcKey );
if ( is_array( $memcValue ) ) {
$cacheEntry = $memcValue;
wfDebug( __METHOD__ . ": got from memcached $memcKey\n" );
}
// Save partitions to memcached
- $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
+ $cache->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
// Save backlink count to memcached
$memcKey = wfMemcKey( 'numbacklinks', md5( $this->title->getPrefixedDBkey() ), $table );
- $wgMemc->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY );
+ $cache->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY );
wfDebug( __METHOD__ . ": got from database\n" );
* @return mixed (string/false)
*/
public function getDiffBody() {
- global $wgMemc;
$this->mCacheHit = true;
// Check if the diff should be hidden from this user
if ( !$this->loadRevisionData() ) {
}
// Cacheable?
$key = false;
+ $cache = ObjectCache::getMainWANInstance();
if ( $this->mOldid && $this->mNewid ) {
$key = $this->getDiffBodyCacheKey();
// Try cache
if ( !$this->mRefreshCache ) {
- $difftext = $wgMemc->get( $key );
+ $difftext = $cache->get( $key );
if ( $difftext ) {
wfIncrStats( 'diff_cache.hit' );
$difftext = $this->localiseLineNumbers( $difftext );
wfIncrStats( 'diff_cache.uncacheable' );
} elseif ( $key !== false && $difftext !== false ) {
wfIncrStats( 'diff_cache.miss' );
- $wgMemc->set( $key, $difftext, 7 * 86400 );
+ $cache->set( $key, $difftext, 7 * 86400 );
} else {
wfIncrStats( 'diff_cache.uncacheable' );
}